<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .square {
            height: 200px;
            width: 200px;
            background: gold;
            /*浮动元素脱离了普通文档流，margin：0 auto不能使用*/
            float: left;

            position: relative;
            left: 50%;
            /*margin-left: -100px;*/

            /*这样写需要考虑兼容性问题*/
            transform: translateX(-50%);
        }
    </style>
</head>
<body>
<div class="square"></div>
</body>
</html>